package com.aaa.java07;

import java.time.LocalDateTime;
import java.util.Arrays;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/7/8 16:52
 * @description：测试对象数组
 * @modified By：
 * @version: 1.0
 */
public class ObjectArray {
    public static void main(String[] args) {
        //创建一个3个员工的数组
        Emp[] emps= new Emp[3];
        LocalDateTime checkInTime1 = LocalDateTime.of(2022, 7, 8, 8, 20, 12);
        LocalDateTime checkOutTime1 =  LocalDateTime.of(2022,7,8,21,30,22);
        Emp  emp1 = new Emp(1,"晋升",checkInTime1,checkOutTime1);
        LocalDateTime checkInTime2 = LocalDateTime.of(2022, 7, 8, 8, 01, 12);
        LocalDateTime checkOutTime2 =  LocalDateTime.of(2022,7,8,21,30,22);
        Emp  emp2 = new Emp(1,"李傲",checkInTime2,checkOutTime2);
        LocalDateTime checkInTime3 = LocalDateTime.of(2022, 7, 8, 8, 15, 12);
        LocalDateTime checkOutTime3 =  LocalDateTime.of(2022,7,8,21,30,22);
        Emp  emp3 = new Emp(1,"周寒",checkInTime3,checkOutTime3);
        emps[0]=emp1;
        emps[1]=emp2;
        emps[2]=emp3;
        System.out.println("排序之前");
        for (Emp emp : emps) {
            System.out.println(emp.name+"上班时间"+emp.checkInTime);
        }
        /*for (int i = 1; i <emps.length ; i++) {
            for (int j = 0; j < emps.length - i; j++) {
                if(emps[j].checkInTime.isAfter(emps[j+1].checkInTime)){
                    //定义一个临时变量
                    Emp xxx= new Emp();
                    xxx=emps[j];
                    emps[j]=emps[j+1];
                    emps[j+1]=xxx;
                }
            }
        }*/
        Arrays.sort(emps);
        System.out.println("排序之后");
        for (Emp emp : emps) {
            System.out.println(emp.name+"上班时间"+emp.checkInTime);
        }
    }
}
